#ifndef LIBCOM_SRC_CMDVALUE_H
#define LIBCOM_SRC_CMDVALUE_H
#include "data.h"

namespace libxcom {

class CmdValue
{
public:
    CmdValue();
    CmdValue(uint8_t *cmd_, int32_t len_);
    CmdValue(int32_t cmd);
    CmdValue(bool cmd);
    CmdValue(const CmdValue &value);

    virtual ~CmdValue();
    static CmdValue Null();

    void Zero();
    bool IsEmpty() const;

    bool operator!=(const CmdValue &value) const;
    bool operator==(const CmdValue &value) const;
    void getNext(int32_t *next, uint8_t sub[], int32_t len);
    int32_t Contains(const CmdValue &value);

    void Show(const std::string &desc = "");

    std::string toString();
    uint8_t *Cmd() const;
    int32_t Length() const;
    uint8_t *CmdAt(int32_t pos) const;
    uint8_t &operator[](int32_t pos) const;
    CmdValue &operator=(const CmdValue &value);
    CmdValue &Insert(int32_t index, const uint8_t value);
    CmdValue &operator+=(const CmdValue &value);
    CmdValue &operator+=(const uint8_t value);
    CmdValue &operator-=(const CmdValue &value);
    CmdValue &operator-=(const uint8_t value);
    CmdValue &operator^(const CmdValue &value);
    CmdValue &operator^(const uint8_t ch);
    CmdValue &TrimLeft(int32_t length);

private:
    inline void copydata(uint8_t *dst, const uint8_t *src, int32_t len);
    bool cmpdata(const uint8_t *dst, const uint8_t *src, int32_t len) const;
    inline void construct(const uint8_t *cmd_, int32_t len_);
    inline void distruct();

private:
    int32_t len;
    uint8_t *cmd;
};
} // namespace libxcom
#endif // LIBCOM_SRC_CMDVALUE_H
